---
- name: Ubuntu Server Provisioning
  hosts: all
  become: True
  gather_facts: False
  vars:
    ruby_version: 2.6.6
    ruby_download_url: http://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.6.tar.gz
    bundler_version: 2.0.2
    rails_version: 6.0.1

  tasks:
    - name: install python
      raw: sudo apt update && sudo apt install -y python3 python3-pip python3-setuptools

    - name: install pip modules
      pip:
        name:
          - simplejson
          - docker-py

    - setup:

    - name: update apt cache
      apt: update_cache=yes

    - name: upgrade packages
      apt: upgrade=dist

    - name: install extra packages
      apt:
        name: "{{ packages }}"
      vars:
        packages:
        - vim
        - tmux
        - mc
        - git
        - net-tools
        - tree

    # --- https://github.com/geerlingguy/ansible-role-docker
    - import_role:
        name: geerlingguy.docker
      vars:
        docker_install_compose: true
        docker_compose_version: "1.25.0"
        docker_compose_path: /usr/local/bin/docker-compose

    - name: append ansible_user to the docker group
      user:
        name: "{{ ansible_user }}"
        group: docker
        append: yes

    #
    # Install Ruby
    #

    # https://github.com/geerlingguy/ansible-role-ruby
    - import_role:
        name: geerlingguy.ruby
      vars:
        workspace: /home/vagrant
        ruby_install_from_source: true
        ruby_install_bundler: false

    - name: install bundler
      shell: "gem install bundler -v {{ bundler_version }}"

    - name: set dir attributes
      file:
        path: "{{ item }}"
        state: directory
        owner: vagrant
        group: vagrant
        mode: 'u+rw'
        recurse: yes
      with_items:
        - /var/lib/gems
        - /usr/local/bin

    #
    # Install Rails
    #

    - name: install curl
      apt:
        name: curl

    - name: install node
      shell: curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

    - name: add yarn pubkey
      shell: curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

    - name: update yarn apt respository
      apt_repository:
        repo: deb https://dl.yarnpkg.com/debian/ stable main
        state: present
        filename: yarn

    - name: install extra packages
      apt:
        name: "{{ packages }}"
      vars:
        packages:
        - vim
        - tmux
        - mc
        - git-core
        - net-tools
        - tree
        - zlib1g-dev
        - build-essential
        - libssl-dev
        - libreadline-dev
        - libyaml-dev
        - libsqlite3-dev
        - sqlite3
        - libxml2-dev
        - libxslt1-dev
        - libcurl4-openssl-dev
        - software-properties-common
        - libffi-dev
        - nodejs
        - yarn

    - name: install rails
      gem:
        name: rails
        version: "{{ rails_version }}"
        state: present
      become: False
